package com.flying.list.exer2;

import java.util.*;

/**
 * @author 刘鹏飞
 * @ClassName KTV
 * @Date 2024/12/30 23:53
 * @Created by 刘鹏飞
 * @Description
 *  TODO:
 *      LinkedList 改造 !!!
 */
public class KTVLinkedList {
    // 创建歌曲容器
    LinkedList<String> songs=new LinkedList<>();

    {
        songs.add("日不落");
        songs.add("像我这样人");
        songs.add("追风少年");
        songs.add("夜空中最亮的星");
    }


    Scanner  scanner=new  Scanner(System.in);;  //

    // 程序开启入口
    private void startKTV(){

        while (true){
            System.out.println(Arrays.toString(songs.toArray()));
            System.out.println("------欢迎来到点歌系统-----------");
            System.out.println("1.添加歌曲至列表");
            System.out.println("2.将歌曲置顶");
            System.out.println("3.将歌曲前移一位");
            System.out.println("4.退出");
            int i = scanner.nextInt();
            switch (i){
                case 1:
                    if (this.addSongs()) {
                        System.out.println("添加成功");
                    }else {System.out.println("添加失败");}
                    break;
                case 2:
                    if (this.setSongFirst()) {
                        System.out.println("歌曲置顶成功");
                    }else {System.out.println("歌曲置顶失败");}
                    break;
                case 3:
                    if (this.moveSong()) {
                        System.out.println("歌曲移位成功");
                    }else {System.out.println("歌曲移位失败");}
                    break;
                case 4:
                    System.exit(0);
            }


        }
    }



    // 添加歌曲
    public boolean addSongs(){
        String song = getSong();
        return songs.add(song);
    }

    // 将歌曲置顶
    public boolean setSongFirst(){
        String song = getSong();
        int i = songs.indexOf(song);
        if (i>0){
            String remove = songs.remove(i);
            songs.addFirst(song);
            return true;
        }
        return false;
    }

    // 将歌曲前移一位 [1,2,3,4,5,6]
    // 即交换两个元素的位置
    public boolean moveSong(){
//        String song = getSong();
        return true;
    }


    private String getSong(){
        System.out.println("请输入歌曲名称: ");
        String song = scanner.next();
        return song;
    }


    public static void main(String[] args) {

        KTVLinkedList  ktv = new KTVLinkedList();

        ktv.startKTV();


    }
}
